package com.yd.app.service.mobile.goodsTypeService;

import com.yd.app.mapper.GoodTypeMapper;
import com.yd.app.mapper.GoodsMapper;
import com.yd.app.mapper.GoodsWeightMapper;
import com.yd.app.service.common.BaseService;
import com.yd.domain.business.*;
import com.yd.domain.commom.PageModel;
import com.yd.domain.searchParam.GoodsSearchParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zy
 * @Desc: 商品分类
 * @Date:  2018/4/28
 * @Param
 */
@Service
public class MGoodsTypeService extends BaseService {

    @Autowired
    GoodTypeMapper goodsTypeMapper;
    /**
     * @Author: zy
     * @Desc: 查询商品导航
     * @Date:  2018/4/28
     * @Param
     */
    public List<GTypeOne> getGoodNav() {
        List<GTypeOne> list=goodsTypeMapper.getTypeOne();
        for(GTypeOne g :list){
            List<GType> gTypeList=goodsTypeMapper.getGTypeList(g.getId());
            if(gTypeList!=null){
                g.setTypeList(getGList(gTypeList));
            }else {//跳过二级直接查询三级
                g.setHaveType("1");
                g.setStyleList(getStyleList(g.getId()));
            }
        }
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 查询商品导航
     * @Date:  2018/4/28
     * @Param
     */
    public List<GTypeOne> getGoodNavTwo() {
        List<GTypeOne> list=goodsTypeMapper.getTypeOne();
        for(GTypeOne g :list){
            List<GType> gTypeList=goodsTypeMapper.getGTypeList(g.getId());
            if(gTypeList!=null){
                g.setTypeList(getGList(gTypeList));
            }
        }
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 二级查询三级
     * @Date:  2018/4/28
     * @Param
     */
    private List<GType> getGList(List<GType> list){
        for(GType g :list){
            g.setStyleList(getStyleList(g.getId()));
        }
        return list;
    }

    /**
     * @Author: zy
     * @Desc: 查询第三级,三级查询了四级
     * @Date:  2018/4/28
     * @Param
     */
    public List<GStyle> getStyleList(String pId){
        List<GStyle> l=goodsTypeMapper.getGStyleList(pId);
        if(l==null){
            l=new ArrayList<>();
        }else{
            for(GStyle g :l){
                g.setpList(goodsTypeMapper.getPListByPId(g.getId()));
            }
        }
        return l;
    }
    public List<GStyleWithGoods> getGStyleWithGoodsList(String pId){
        List<GStyleWithGoods> list=goodsTypeMapper.getGStyleWithGoodsList(pId);
        return list;
    }
    /**
     * @Author: zy
     * @Desc: 根据pId获取品型
     * @Date:  2018/5/10
     * @Param
     */
    public List<PinXing> getPxByPid(String pId) {
        List<PinXing> list=goodsTypeMapper.getPListByPId(pId);
        return list;
    }
}
